﻿using mars_client.csharp.cache;
using mars_client.csharp.model;
using mars_client.csharp.AO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using mars_client.gui.window;
using mars_client.csharp.model.vo;

namespace mars_client.csharp.AO
{
    public class MainWindowAOImpl : MainWindowAO
    {
        private MainWindowAOImpl() { }
        private readonly static MainWindowAOImpl instance = new MainWindowAOImpl();
        internal static MainWindowAOImpl Instance
        {
            get
            {
                return instance;
            }
        }

        GuiCache guic = GuiCache.Instance;
        UserCache uc = UserCache.Instance;

        public void login(UserVO vo)
        {
            if(vo == null)
            {
                MessageBox.Show("账号或密码错误，请重新输入");
            }
            else
            {
                App.Current.Dispatcher.Invoke(() =>
                {
                    LoginWindow lw = (LoginWindow)guic.getGui("LoginWindow");
                    MainWindow mw = (MainWindow)guic.getGui("MainWindow");
                    mw.Show();
                    lw.Close();
                    uc.userVO = vo;
                });
            }
        }
    }
}
